Skip to content

Conversation

@sharmagot
Copy link
Collaborator

@sharmagot sharmagot commented Dec 8, 2025

This MR improves TOTP validation in the Vertica Python driver by enforcing strict 6-digit numeric checks.
Invalid TOTPs (alphanumeric, incorrect length, or with extra spaces) are now blocked locally and return a consistent error message:
“Invalid TOTP: Please enter a valid 6-digit numeric code.”
This prevents invalid authentication requests from being sent to the server and improves user experience.

@sharmagot sharmagot self-assigned this Dec 8, 2025
@sharmagot sharmagot requested a review from ssharieff21 December 8, 2025 05:20
try:
print("Enter TOTP: ", end="", flush=True)
ready, _, _ = select.select([sys.stdin], [], [], timeout_seconds)
if ready:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we wait 5mins for the user to enter TOTP?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Siva, if the user does not provide the TOTP within 5 minutes, the session should expire—meaning the connection between the driver and the server should be terminated.

result = validate_totp_code(totp_input, totp_is_valid=None)
if not result.ok:
msg = result.message or INVALID_TOTP_MSG
print(msg)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this print(msg) for debugging purpose, please remove it

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Siva, I have removed the debug message .

@sivaalamp
Copy link
Collaborator

MR description did not cover all the issues that addressed. Please update the MR description accordingly.

INVALID_TOTP_MSG = 'Invalid TOTP: Please enter a valid 6-digit numeric code.'

if validate_totp_code is not None:
result = validate_totp_code(self.totp, totp_is_valid=None)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

validate_totp_code function definition is missing.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Siva , Added the definition for validate_totp_code.

Copy link
Collaborator

@sivaalamp sivaalamp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments are added

# Remove common separators inside the code
# Spaces, hyphens, underscores, dots, and common dash-like characters
separators = {' ', '\t', '\n', '\r', '\f', '\v', '-', '_', '.',
'\u2012', '\u2013', '\u2014', '\u2212', '\u00B7', '\u2027', '\u30FB'}
Copy link
Collaborator

@sivaalamp sivaalamp Jan 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If user enters the TOTP with - or _ or ., your code is removing them without giving error message. Removing the trailing or leading white spaces is acceptable, but if user deliberately enters these special characters, should we remove them or should we warn user that invalid characters are not allowed.

# All good
return TotpValidationResult(True, s, '')
except Exception:
# Fallback generic error
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no exception handling, it is just like function return. Handle the exception when we use try catch block



def validate_totp_code(raw_code: str, totp_is_valid=None) -> TotpValidationResult:
"""Validate and normalize a user-supplied TOTP value.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

totp_is_valid is written as it is reserved for server side checks. but validate_totp_code function itself is called to do the checks before sending to the server. Something is not right, can you please verify?


# All good
return TotpValidationResult(True, s, '')
except Exception:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the tests are not updated to test these new error message?

Copy link
Collaborator

@sivaalamp sivaalamp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests are not updated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants